package cc.mrbird.febs.power.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.power.entity.PermissionInfo;
import cc.mrbird.febs.power.service.IPermissionInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MrBird
 */
@RestController
@RequestMapping("/power/permission-info")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PermissionInfoController {

    private final IPermissionInfoService iPermissionInfoService;

    /**
     * 分页获取权限信息
     * @param page
     * @param permissionInfo
     * @return
     */
    @GetMapping("/page")
    public R getPermissionByPage(Page page,PermissionInfo permissionInfo) {
        return R.ok(iPermissionInfoService.page(page,Wrappers.<PermissionInfo>lambdaQuery().like(permissionInfo.getPermissionName()!=null,PermissionInfo::getPermissionName,permissionInfo.getPermissionName())));
    }

    /**
     * 获取所有权限
     * @return
     */
    @GetMapping
    public R getPermissionInfo() {
        return R.ok(iPermissionInfoService.list());
    }

    /**
     * 新增操作
     * @param permissionInfo
     * @return
     */
    @PostMapping("/PermissionInfoAdd")
    public R PermissionInfoAdd(PermissionInfo permissionInfo) {
        return R.ok(iPermissionInfoService.save(permissionInfo));
    }

    /**
     * 修改操作
     * @param permissionInfo
     * @return
     */
    @PutMapping("/PermissionInfoEdit")
    public R PermissionInfoEdit(PermissionInfo permissionInfo) {
        return R.ok(iPermissionInfoService.updateById(permissionInfo));
    }

    /**
     * 通过ID删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R PermissionInfoDel(@PathVariable Integer id) {
        return R.ok(iPermissionInfoService.removeById(id));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/man/ids")
    public R PermissionInfosDel(@RequestBody List<Integer> ids) {
        return R.ok(iPermissionInfoService.removeByIds(ids));
    }


}
